<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
            role: '',
            items:[],
            adminItems: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'home',
                    title: '系统首页'
                },
                {
                    icon: 'el-icon-user-solid',
                    index: 'guize',
                    title: '学院管理'
                },
                
                {
                    icon: 'el-icon-user-solid',
                    index: 'baodao',
                    title: '发布报道'
                },
                {
                    icon: 'el-icon-s-custom',
                    index: 'zhiyin',
                    title: '交通指引'
                },
                {
                    icon: 'el-icon-s-custom',
                    index: 'zhiyuanzhe',
                    title: '志愿者信息'
                },
                /* {
                    icon: 'el-icon-document',
                    index: 'tongji',
                    title: '宿舍管理'
                }, */
                {
                    icon: 'el-icon-document',
                    index: 'shenhe',
                    title: '在线审核'
                }
            ],
            stuItems: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'home',
                    title: '系统首页'
                },
                {
                    icon: 'el-icon-user-solid',
                    index: 'zhinan',
                    title: '院系指南'
                },
                {
                    icon: 'el-icon-s-custom',
                    index: 'xinxi',
                    title: '个人信息'
                },
                {
                    icon: 'el-icon-s-custom',
                    index: 'jiaofei',
                    title: '交通信息'
                },
                {
                    icon: 'el-icon-document',
                    index: 'sushe',
                    title: '在线查看宿舍'
                },
                {
                    icon: 'el-icon-document',
                    index: 'lianxi',
                    title: '联系志愿者'
                }/* ,
                {
                    icon: 'el-icon-document',
                    index: 'dayin',
                    title: '报道单自助打印'
                } */
            ]
        };
    },

    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
        this.role = JSON.parse(localStorage.getItem('student')).role;
        if(this.role == 0){
            this.items=this.stuItems
        }
        if(this.role==1){
            this.items=this.adminItems
        }
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
